/*
 * Copyright 2004-2006 公司名
 * 本软件及其所有拷贝的名称，与光盘上或本软件中注明的公司同在。
 * 本软件及文档享有版权，并受国家版权法及国际协约条款的保护。
 * 您不可以从本软件中去掉其版权声明；并保证为本软件的拷贝（本部或部分）复制版权声明。
 * 您同意制止以任何形式非法拷贝本软件及文档。
 * 版权信息参见：
 *      http://www.companyname.cn/licenses
 */

package com.companyname.common.sysframe.service;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

import com.companyname.common.base.web.service.AbstractListService;
import com.companyname.common.sysframe.define.OrgStatus;
import com.companyname.common.sysframe.manager.OrgManager;
import com.companyname.common.sysframe.view.foreveryone.OrgList4EveryOne;

/**
 * <p>Title: 机构</p>
 * <p>Description: 机构 Org </p>
 * <p>Copyright: Copyright (c) 2004-2006</p>
 * <p>Company: 公司名</p>
 * @ $Author: 作者名 $
 * @ $Date: 创建日期 $
 * @ $Revision: 1.0 $
 * @ created in 创建日期
 *
 */

public class FindOrgsService extends AbstractListService
{
        static Logger logger = Logger.getLogger(FindOrgsService.class);

        private OrgManager orgManager;

        public void setOrgManager(OrgManager orgManager)
        {
                this.orgManager = orgManager;
        }

        /** 获取列表的models */
        public List getList(HttpServletRequest request)
        {
                // 获取翻页结果集合
                logger.debug("1. 获取查询条件.....");
                // 获取查询条件
                String code = this.getValueFromRequestParameter(request,"code");
                String superOrgId = this.getValueFromRequestParameter(request,"superOrgId");
                String name = this.getValueFromRequestParameter(request,"name");
                String country = this.getValueFromRequestParameter(request,"country");
                String province = this.getValueFromRequestParameter(request,"province");
                String city = this.getValueFromRequestParameter(request,"city");
                String street = this.getValueFromRequestParameter(request,"street");
                String office = this.getValueFromRequestParameter(request,"office");
                String linkMan = this.getValueFromRequestParameter(request,"linkMan");
                String phone = this.getValueFromRequestParameter(request,"phone");
                String fax = this.getValueFromRequestParameter(request,"fax");
                String email = this.getValueFromRequestParameter(request,"email");

                String orderBy = this.getValueFromRequestParameter(request,"orderBy","org.pri");
                String sortType = this.getValueFromRequestParameter(request,"sortType","asc");
                logger.debug("2. 获取查询条件完毕,开始查询.....");
                return this.orgManager.findOrgs(code,
                                                superOrgId,
                                                name,
                                                country,
                                                province,
                                                city,
                                                street,
                                                office,
                                                linkMan,
                                                phone,
                                                fax,
                                                email,
                                                Integer.toString(OrgStatus.VALID),
                                                orderBy,
                                                sortType);
        }

        /** model -> viewer */
        public Object getViewer(HttpServletRequest request)
        {
                // 根据request里面提供的参数做角色、权限判断,然后返回对应的viewer
                return new OrgList4EveryOne(); // foreveryone
        }

}
